package com.stt.order.design.controller;

import com.stt.order.model.Order;
import com.stt.order.design.service.PromotionStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 促销策略计算控制器，提供订单折扣计算相关接口
 */
@RestController
@RequestMapping("/api/orders/v2")
public class PromotionStrategyController {
    
    @Autowired
    private PromotionStrategyService strategyService;

    /**
     * 订单折扣计算接口，对传入的订单对象执行促销策略计算
     * @param order 需要计算折扣的订单对象（请求体自动反序列化）
     * @return 包含折扣计算结果的完整订单对象
     */
    @PostMapping("/calculate")
    public Order calculateOrderDiscount(@RequestBody Order order) {
        strategyService.calculateDiscount(order);
        return order;
    }
} 